/**
*   @file    Dbgu.c
*   MRTB-05 Project
*
*   @{
*/
/*==================================================================================================
*   Project              : MRTB-05
*   Platform             : SBC6000X, AT91SAM9261S
*   Build Version        : Keil uVision 4.53
*
*   (c) Copyright VNE Corporation
*   All Rights Reserved.
==================================================================================================*/
#ifndef REG_MARCOS_H /* REG_MARCOS_H */
#define REG_MARCOS_H

#ifdef __cplusplus
extern "C"{
#endif

#include "MemType.h"
/**
*  Bit masks declarations.
*/
#define BIT31   ((uint32)0x80000000UL)
#define BIT30   ((uint32)0x40000000UL)
#define BIT29   ((uint32)0x20000000UL)
#define BIT28   ((uint32)0x10000000UL)
#define BIT27   ((uint32)0x08000000UL)
#define BIT26   ((uint32)0x04000000UL)
#define BIT25   ((uint32)0x02000000UL)
#define BIT24   ((uint32)0x01000000UL)
#define BIT23   ((uint32)0x00800000UL)
#define BIT22   ((uint32)0x00400000UL)
#define BIT21   ((uint32)0x00200000UL)
#define BIT20   ((uint32)0x00100000UL)
#define BIT19   ((uint32)0x00080000UL)
#define BIT18   ((uint32)0x00040000UL)
#define BIT17   ((uint32)0x00020000UL)
#define BIT16   ((uint32)0x00010000UL)
#define BIT15   ((uint32)0x00008000UL)
#define BIT14   ((uint32)0x00004000UL)
#define BIT13   ((uint32)0x00002000UL)
#define BIT12   ((uint32)0x00001000UL)
#define BIT11   ((uint32)0x00000800UL)
#define BIT10   ((uint32)0x00000400UL)
#define BIT9    ((uint32)0x00000200UL)
#define BIT8    ((uint32)0x00000100UL)
#define BIT7    ((uint32)0x00000080UL)
#define BIT6    ((uint32)0x00000040UL)
#define BIT5    ((uint32)0x00000020UL)
#define BIT4    ((uint32)0x00000010UL)
#define BIT3    ((uint32)0x00000008UL)
#define BIT2    ((uint32)0x00000004UL)
#define BIT1    ((uint32)0x00000002UL)
#define BIT0    ((uint32)0x00000001UL)

/**
* 8 bits memory write macro
*/
#define REG_WRITE8(address, value)        ((*(volatile uint8*)(address))=  (uint8)(value))
/**
*  bits memory write macro.
*/
#define REG_WRITE16(address, value)       ((*(volatile uint16*)(address))= (uint16)(value))
/**
* 32 bits memory write macro.
*/
#define REG_WRITE32(address, value)       ((*(volatile uint32*)(address))= (uint32)(value))
/**
* bits memory read macro.
*/
#define REG_READ8(address)                (*(volatile uint8*)(address))
/**
* 16 bits memory read macro.
*/
#define REG_READ16(address)               (*(volatile uint16*)(address))
/**
* 32 bits memory read macro.
*/
#define REG_READ32(address)               (*(volatile uint32*)(address))
/**
* 8 bits indexed memory write macro.
*/
#define REG_AWRITE8(address, i, value)     (REG_WRITE8 ((address)+(uint32)(i), (value)))
/**
* 16 bits indexed memory write macro.
*/
#define REG_AWRITE16(address, i, value)    (REG_WRITE16((address)+((uint32)(((uint32)(i))<<1U)), (value)))
/**
* 32 bits indexed memory write macro.
*/
#define REG_AWRITE32(address, i, value)    (REG_WRITE32((address)+((uint32)(((uint32)(i))<<2U)), (value)))
/**
* 8 bits indexed memory read macro.
*/
#define REG_AREAD8(address, i )            (REG_READ8 ((address)+(uint32)(i)))
/**
* 16 bits indexed memory read macro.
*/
#define REG_AREAD16(address, i)            (REG_READ16((address)+((uint32)(((uint32)(i))<<1U))))
/**
* 32 bits indexed memory read macro.
*/
#define REG_AREAD32(address, i)            (REG_READ32((address)+((uint32)(((uint32)(i))<<2U))))
/**
* 8 bits bits clearing macro.
*/
#define REG_BIT_CLEAR8(address, mask)     ((*(volatile uint8*)(address))&= ((uint8)~((uint8)(mask))))
/**
* 16 bits bits clearing macro.
*/
#define REG_BIT_CLEAR16(address, mask)    ((*(volatile uint16*)(address))&= ((uint16)~((uint16)(mask))))
/**
* 32 bits bits clearing macro.
*/
#define REG_BIT_CLEAR32(address, mask)    ((*(volatile uint32*)(address))&= ((uint32)~((uint32)(mask))))
/**
* 8 bits bits getting macro.
*/
#define REG_BIT_GET8(address, mask)       ((*(volatile uint8*)(address))& (uint8)(mask))
/**
* 16 bits bits getting macro.
*/
#define REG_BIT_GET16(address, mask)      ((*(volatile uint16*)(address))& (uint16)(mask))
/**
* 32 bits bits getting macro.
*/
#define REG_BIT_GET32(address, mask)      ((*(volatile uint32*)(address))& (uint32)(mask))
/**
* 8 bits bits setting macro.
*/
#define REG_BIT_SET8(address, mask)       ((*(volatile uint8*)(address))|= (uint8)(mask))
/**
* 16 bits bits setting macro.
*/
#define REG_BIT_SET16(address, mask)      ((*(volatile uint16*)(address))|= (uint16)(mask))
/**
* 32 bits bits setting macro.
*/
#define REG_BIT_SET32(address, mask)      ((*(volatile uint32*)(address))|= (uint32)(mask))
/**
* 8 bit clear bits and set with new value
*/
#define REG_RMW8(address, mask, value)    (REG_WRITE8((address), ((REG_READ8(address)& ((uint8)~((uint8)(mask))))| ((uint8)(value)))))
/**
* 16 bit clear bits and set with new value
* In the current implementation, it is caller's (user's) responsability to make sure that
*       value has only "mask" bits set - (value&~mask)==0
*/
#define REG_RMW16(address, mask, value)   (REG_WRITE16((address), ((REG_READ16(address)& ((uint16)~((uint16)(mask))))| ((uint16)(value)))))
/**
* 32 bit clear bits and set with new value
* In the current implementation, it is caller's (user's) responsability to make sure that
*       value has only "mask" bits set - (value&~mask)==0
*/
#define REG_RMW32(address, mask, value)   (REG_WRITE32((address), ((REG_READ32(address)& ((uint32)~((uint32)(mask))))| ((uint32)(value)))))

#ifdef __cplusplus
}
#endif
#endif  /* REG_MARCOS_H */
